/**
 * 
 */
package com.thor.palmmall.rest.product.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.product.AProductChangeQueryParam;
import com.thor.palmmall.spi.product.SProductChangeQueryParam;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SProductChangeQueryParamConverter
    implements Converter<AProductChangeQueryParam, SProductChangeQueryParam> {

  public static SProductChangeQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SProductChangeQueryParamConverter();
    return instance;
  }

  private static SProductChangeQueryParamConverter instance;

  private SProductChangeQueryParamConverter() {
  }

  @Override
  public SProductChangeQueryParam convert(AProductChangeQueryParam source) {
    if (source == null)
      return null;

    SProductChangeQueryParam target = new SProductChangeQueryParam();
    target.setContracts(new ArrayList<UCN>());
    if (source.getContracts() != null)
      for (UCN sourceContract : source.getContracts())
        target.getContracts().add(UCN.newInstance(sourceContract));
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(source.getStores());
    target.setUserGroups(new ArrayList<KV>());
    for (KV sourceUserGroup : source.getUserGroups())
      target.getUserGroups().add(KV.newInstance(sourceUserGroup));
    target.setOrder(source.getOrder());

    return target;
  }

}
